package com.project.Servlet;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.project.Bean.UserBean;
import com.project.Service.IUserService;
import com.project.Service.Impl.ServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @Title: FindAllServlet
 * @Package: com.project.Servlet
 * @Description:
 * @Author: Liang-Xie
 * @Date: 2022/6/21 - 15:45
 */
@SuppressWarnings("all")
public class FindAllServlet extends HttpServlet {
    private IUserService iUserService=new ServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       req.setCharacterEncoding("utf-8");
       resp.setContentType("text/html;charset=utf-8");
        List<UserBean> list=iUserService.findAll();
        ObjectMapper om=new ObjectMapper();
        om.registerModule(new JavaTimeModule());
        String str=om.writeValueAsString(list);
        resp.getWriter().print(str);


    }
}
